CurrentVersion = 4 //dev only
GM.Name 	= "ReDead (v1.0"..CurrentVersion..")"
GM.Author 	= "Rambo_6, Adapted by Entoros"
GM.Email 	= "sechs.llsc.us@gmail.com"
GM.Website 	= "hai2u.com"
GM.GameLength = 20
GM.Help = "Shoot the zombies.\nGather the vials.\nUpgrade your weapons."
GM.PlayerCanNoClip = false

TEAM_HUMANS,TEAM_SURVIVORS,TEAM_HUMAN = 1,1,1
TEAM_ZOMBIES,TEAM_UNDEAD = 2,2
TEAM_SPECTATOR,TEAM_SPECTATORS = 3,3

function GM:SetupTeams()
	team.SetUp(1, "Survivors", Color(70, 80, 220, 255))  
	team.SetUp(2, "Zombies", Color(180, 20, 20, 255)) 
	team.SetUp(3, "Joining", Color(20, 180, 180, 255)) 
end

function GM:EndGame()
	if GameInfo.GameOver then return end

	GameInfo.GameOver = true
	Awards.Calculate()
	
	for k,v in pairs(player.GetAll()) do
		v:GodEnable()
	end
	
	for k, v in pairs(player.GetAll()) do
		if not v:Alive() or v:Team() == TEAM_UNDEAD or (v:GetActiveWeapon() == NULL or v:GetActiveWeapon() == nil) then
			if GameInfo.MusicEnabled then
				v:ClientSound(ChooseRandom(GameSounds.LoseMusic))
			end	
		else
			if GameInfo.MusicEnabled then
				v:ClientSound(ChooseRandom(GameSounds.WinMusic))
			end
		end
	end	
	timer.Create("NextMapTimer", 3, 1, GAMEMODE.NextMap, GAMEMODE)
	timer.Create("NoticeTimer", GameInfo.ScoreDelay - 3, 1, GAMEMODE.LoadNotice, GAMEMODE)
	timer.Create("ScoreTimer", GameInfo.ScoreDelay, 1, GAMEMODE.LoadNextMap, GAMEMODE)
end

function GM:NextMap()
	for k, v in pairs(player.GetAll()) do
		v:ChatPrint("The next map will be: "..game.GetMapNext())
	end
end

function GM:LoadNotice()
	for k, v in pairs(player.GetAll()) do
		v:ChatPrint("Loading next map...")
	end
end

function GM:LoadNextMap()
	game.LoadNextMap()
end

function GM:PlayerShouldTakeDamage( ply, attacker )
	if attacker:IsPlayer() then
		if ply:Team() == attacker:Team() and attacker != ply then
			return false
		else
			return true
		end
	else
		return true
	end
end

function WriteToFile(ID,tbl)
	local Name = "redead/"..ID..".txt"
	local str
	for k,v in pairs(tbl) do
		if str == nil then
			str = tostring(v)
		else
			str = str.."~"..tostring(v)
		end
	end
	file.Write(Name, str) 
end

function OpenFromFile(ID)
	local loaded = {}
	local Name = "redead/"..ID..".txt"
	if file.Exists(Name) then
		loaded = string.Explode("~",file.Read(Name))
	end
return loaded end 